//
//  CANavigationController.m
//  Conva
//
//  Created by cruise on 2018/1/3.
//  Copyright © 2018年 com.conva. All rights reserved.
//

#import "LMNavigationController.h"

@interface LMNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation LMNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    id target = self.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    [self.interactivePopGestureRecognizer setEnabled:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+(void) initialize {
    [LMNavigationController setupNavTheme];
}

// 设置导航栏的主题
+(void)setupNavTheme{
    // 设置导航样式
    [UINavigationBar appearance].translucent = NO;
    [[UINavigationBar appearance] setBarTintColor:RGBCOLOR(241, 90, 36)];
    [UINavigationBar appearance].tintColor = RGBCOLOR(241, 90, 36);
    [UINavigationBar appearance].backgroundColor =  [UIColor whiteColor];
    [UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont systemFontOfSize:16]};
    
    // 设置状态栏的样式
    // xcode5以上，创建的项目，默认的话，这个状态栏的样式由控制器决定
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    NSLog(@"%ld", self.viewControllers.count);
    if (self.viewControllers.count){
        viewController.hidesBottomBarWhenPushed = YES;
        
        [viewController.navigationItem setHidesBackButton:YES animated:NO];
        
        [viewController.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)]];
    }
    [super pushViewController:viewController animated:animated];
}

-(void) backAction {
    [self popViewControllerAnimated:YES];
}

@end
